package com.sunzhe.cms.tag;

import com.ibeetl.cms.web.query.CatalogQuery;
import com.ibeetl.cms.entity.CmsCatalog;
import com.ibeetl.cms.service.CmsCatalogService;
import org.beetl.core.tag.GeneralVarTagBinding;
import org.beetl.sql.core.SQLManager;
import org.beetl.sql.core.engine.PageQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@Scope("prototype") // Tag是每次使用功能都会创建，因此使用prototype
public class TestTag extends GeneralVarTagBinding {

	@Autowired
    CmsCatalogService catalogService;

	@Autowired
	@Qualifier("baseDataSourceSqlManagerFactoryBean")
	protected SQLManager sqlManager;
	@Override
	public void render() {
		CatalogQuery condition = new CatalogQuery();
		PageQuery<CmsCatalog> page = condition.getPageQuery();
		List l = sqlManager.execute("SELECT DISTINCT (type),name FROM cms_catalog ORDER BY type", CmsCatalog.class,page);


		System.out.println(l);
		this.binds(l);// 标签体上必须有var="" 的属性
		this.doBodyRender();
	}

}
